package com.tz.actions;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;

import java.util.Map;

/**
 * Created by Administrator on 2016/9/29.
 */
@Namespace("/ognl")
@Result(name = "success", location = "/WEB-INF/jsp/result3.jsp")
public class CountAction extends ActionSupport {

    @Action("count")
    public String count() {
        ActionContext context = ActionContext.getContext();
        Map<String, Object> session = context.getSession();
        Object count = session.get("count");
        if (count == null) {
            count = 1;
        } else {
            count = (Integer) count + 1;
        }
        session.put("count", count);
        return SUCCESS;
    }
}
